import WeexNativeModule from "../../common/WeexNativeModule";
import ACApi from "../../common/http/ACApi";
import StringUtils from "../../common/util/StringUtils";
import JsonFilter from "../../common/util/JsonFilter";
import DateUtil from "../../common/util/DateUtil";
let instance;
let taskcode;
let loginUser = {};
class EMNewMainCABGControl{
    constructor(vue){
        instance = vue;
        this.getLoginUser();
    }
    getLoginUser(){
        let self = this;
        WeexNativeModule.getLoginUser(function (res) {
            let param = JSON.parse(res.loginUser);
            loginUser.id = param.id;
            loginUser.orgid = param.orgid;
            loginUser.name = param.username;
            self.initData();
        })

    }
    initData(){
        let self = this;
        WeexNativeModule.getParam(function (res) {
            let param = JSON.parse(res.param);
            taskcode = param.taskcode;
            self.refreshData();
        })
    }
    refreshData(){
        WeexNativeModule.showProgressDialog("正在获取数据，请稍等...")
        ACApi.getCAVGDetail(taskcode,{
            onSuccess:function (res) {
                WeexNativeModule.dimissProgressDialog();
                let result = JSON.parse(res);
                // WeexNativeModule.alert(result.result)
                if (result.result) {
                    instance.DiagTreatModel.DECISION_CABG_TIME = result.result.DECISION_CABG_TIME;
                    instance.DiagTreatModel.START_CABG_TIME = result.result.START_CABG_TIME;
                    instance.DiagTreatModel.END_CABG_TIME = result.result.END_CABG_TIME;
                }
            },
            onError:function (err) {
                WeexNativeModule.dimissProgressDialog();
            }
        })
    }
    saveData(){
        if(StringUtils.isEmpty(taskcode)){
            return;
        }
        let content = {};
        content = instance.DiagTreatModel;
        content.ORDER_ID = taskcode;
        WeexNativeModule.showProgressDialog("正在保存数据，请稍等...")
        ACApi.saveCABG(content,{
            onSuccess:function (res) {
                WeexNativeModule.dimissProgressDialog();
                WeexNativeModule.toast("保存成功");
                WeexNativeModule.finish();
            },
            onError:function (err) {
                WeexNativeModule.dimissProgressDialog();
                WeexNativeModule.toast("保存失败");
            }
        })
    }
    selectedDateTime(type,defaulttime){
        let defaultdate;
        if(!StringUtils.isEmpty(defaulttime)){
            defaultdate = DateUtil.formatTime(
                new Date(defaulttime),'yyyy-MM-dd hh:mm');
        }else {
            defaultdate = DateUtil.formatTime(
                new Date(),'yyyy-MM-dd hh:MM');
        }
        WeexNativeModule.selectDateTime(defaultdate,false,true,true,true,true,false,
            false,'','',function (res) {
                let result = DateUtil.formatTime(
                    new Date(res.data), 'yyyy-MM-dd hh:mm');
                if(type == 0){
                    instance.DiagTreatModel.DECISION_CABG_TIME = result;
                }
                if(type == 1){
                    instance.DiagTreatModel.START_CABG_TIME = result;
                }
                if(type == 2){
                    instance.DiagTreatModel.END_CABG_TIME = result;
                }
            });
    }
    finish(){
        WeexNativeModule.finish();
    }
}
export default EMNewMainCABGControl;